﻿using Architecture.API.Application.TraceabilityCommand.SlaughterCommand;
using MediatR;
using Traceability.Domain.Service.SlaughterServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.SlaughterCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class DeletedSlaughterCommandHandler : IRequestHandler<DeletedSlaughterCommand, int>
    {
        /// <summary>
        /// 屠宰服务
        /// </summary>
        protected readonly ISlaughterService slaughterService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="slaughterService">屠宰服务</param>
        public DeletedSlaughterCommandHandler(ISlaughterService slaughterService)
        {
            this.slaughterService = slaughterService;
        }

        /// <summary>
        /// 删除构造函数
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(DeletedSlaughterCommand request, CancellationToken cancellationToken)
        {
            return await slaughterService.DeleteSlaughters(request.slaughterId,request.userName);
        }
    }
}
